﻿Imports KelControl

Public Class KelControlFrom
    Private Controleur As KelControl

    Private Sub KelControlFrom_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        niKelControl.Visible = False
    End Sub

    Private Sub KelControlFrom_Leave(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Leave
        Controleur.arret()
    End Sub

    Private Sub KelControlFrom_Shown(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Shown
        Try
            Controleur = New KelControl()
            Dim tcbSitesWebStart As TimerCallBack = AddressOf Me.cbSitesWebStart
            Dim tcbSitesWebEnd As TimerCallBack = AddressOf Me.cbSitesWebEnd
            Dim tcbServeursStart As TimerCallBack = AddressOf Me.cbServeursStart
            Dim tcbServeursEnd As TimerCallBack = AddressOf Me.cbServeursEnd
            Dim tcbWebServicesStart As TimerCallBack = AddressOf Me.cbWebServiceStart
            Dim tcbWebServicesEnd As TimerCallBack = AddressOf Me.cbWebServiceEnd

            Controleur.cbOnStartSiteWeb = tcbSitesWebStart
            Controleur.cbOnEndSiteWeb = tcbSitesWebEnd
            Controleur.cbOnStartServeurs = tcbServeursStart
            Controleur.cbOnEndServeurs = tcbServeursEnd
            Controleur.cbOnStartWebServices = tcbWebServicesStart
            Controleur.cbOnEndWebServices = tcbWebServicesEnd

            Controleur.initAllThread()
        Catch ex As Exception
            MsgBox(ex.Message)
            Me.Close()
        End Try
    End Sub

    Public Sub cbSitesWebStart()
        If (Me.InvokeRequired) Then
            Invoke(Controleur.cbOnStartSiteWeb)
        Else
            Me.lEtatSites.Text = "Verification ..."
            Me.btnVerifSitesWeb.Text = "Verification ..."
            Me.lNextSites.Text = ""
            Me.btnVerifSitesWeb.Enabled = False
        End If
    End Sub

    Public Sub cbServeursStart()
        If (Me.InvokeRequired) Then
            Invoke(Controleur.cbOnStartServeurs)
        Else
            Me.lEtatServeurs.Text = "Verification ..."
            Me.btnVerifServeurs.Text = "Verification ..."
            Me.lNextServeurs.Text = ""
            Me.btnVerifServeurs.Enabled = False
        End If
    End Sub

    Public Sub cbWebServiceStart()
        If (Me.InvokeRequired) Then
            Invoke(Controleur.cbOnStartWebServices)
        Else
            Me.lEtatServices.Text = "Verification ..."
            Me.btnVerifServices.Text = "Verification ..."
            Me.lNextServices.Text = ""
            Me.btnVerifServices.Enabled = False
        End If
    End Sub

    Public Sub cbSitesWebEnd()
        If (Me.InvokeRequired) Then
            Invoke(Controleur.cbOnEndSiteWeb)
        Else
            Me.lEtatSites.Text = "Ok"
            Me.btnVerifSitesWeb.Text = "Relancer"
            Me.lNextSites.Text = "Prochaine : " & Date.Now.AddMinutes(Controleur.itSitesWeb)
            Me.btnVerifSitesWeb.Enabled = True
        End If
    End Sub

    Public Sub cbServeursEnd()
        If (Me.InvokeRequired) Then
            Invoke(Controleur.cbOnEndServeurs)
        Else
            Me.lEtatServeurs.Text = "Ok"
            Me.btnVerifServeurs.Text = "Relancer"
            Me.lNextServeurs.Text = "Prochaine : " & Date.Now.AddMinutes(Controleur.itServeurs)
            Me.btnVerifServeurs.Enabled = True
        End If
    End Sub

    Public Sub cbWebServiceEnd()
        If (Me.InvokeRequired) Then
            Invoke(Controleur.cbOnEndWebServices)
        Else
            Me.lEtatServices.Text = "Ok"
            Me.btnVerifServices.Text = "Relancer"
            Me.lNextServices.Text = "Prochaine : " & Date.Now.AddMinutes(Controleur.itServices)
            Me.btnVerifServices.Enabled = True
        End If
    End Sub

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnVerifSitesWeb.Click
        Controleur.startThreadSiteWeb()
    End Sub

    Private Sub btnVerifServeurs_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnVerifServeurs.Click
        Controleur.startThreadServeurs()
    End Sub

    Private Sub btnVerifServices_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnVerifServices.Click
        Controleur.startThreadWebServices()
    End Sub

    Private Sub niKelControl_DoubleClick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles niKelControl.DoubleClick
        Me.Visible = True
        Me.WindowState = FormWindowState.Normal
        niKelControl.Visible = False
    End Sub

    Private Sub KelControlFrom_SizeChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.SizeChanged
        If (Me.WindowState = FormWindowState.Minimized) Then
            niKelControl.Visible = True
            Me.Visible = False
        End If
    End Sub
End Class
